﻿namespace Leetcode.N1872;
public class Solution
{
    public int StoneGameVIII(int[] stones)
    {
        var n = stones.Length;
        var sums = new int[n + 1];
        for (int i = 1; i <= n; i++)
        {
            sums[i] = sums[i - 1] + stones[i - 1];
        }

        var ans = new int[n];
        ans[n - 1] = sums[n];

        for (int i = n - 2; i >= 1; i--)
        {

            ans[i] = Math.Max(ans[i + 1], sums[i + 1] - ans[i + 1]);
        }
        return ans[1];
    }
}